package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Microshop;

public class MicroshopDao extends SuperDao {

	/**
	 * 保存
	 */
	public void addMicroshop(Microshop microshop) {
		super.save(microshop);
	}
	
	public void delMicroshop(Microshop microshop) {
		super.delete(microshop);
	}
	
	/**
	 * 修改微店地址
	 */
	public void updateMicroshop(Microshop microshop) {
		StringBuilder sb = new StringBuilder();
		sb.append("update ubcenter.b_micro_shop set url = '");
		sb.append(microshop.getUrl());
		sb.append("' where micro_id = ");
		sb.append(microshop.getId());
		super.executeUpdate(sb.toString());
	}
	
	/**
	 * 通过eaId查询微店地址
	 */
	public Object getMicroshopUrlByEaid(Long eaId) {
		String hql = "from Microshop where eaId = ?";
		List<Object> objects = getObject(hql, new Object[]{ eaId });
		if (objects.isEmpty()) {
			return null;
		}
		return objects.get(0);
	}
	
	/**
	 * 通过microId查询微店地址
	 */
	public Object getMicroshopUrlById(Long microId) {
		String hql = "from Microshop where id = ?";
		List<Object> objects = getObject(hql, new Object[]{ microId });
		if (objects.isEmpty()) {
			return null;
		}
		return objects.get(0);
	}

}
